home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-16 | 9.7 KB | 361 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: Part.cpp
- // Release Version: $ ODF 3 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Form.hpp"
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- #ifndef FRAME_H
- #include "Frame.h"
- #endif
-
- #ifndef DIALOG_H
- #include "Dialog.h"
- #endif
-
- #ifndef VIEW_H
- #include "View.h"
- #endif
-
- #ifndef SCROLLED_H
- #include "ScrollEd.h"
- #endif
-
- #ifndef BINDING_K
- #include "Binding.k"
- #endif
-
- // ----- Framework Layer -----
-
- #ifndef FWABOUT_H
- #include "FWAbout.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- #ifndef FWITERS_H
- #include "FWIters.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSCLBAR_H
- #include "FWSclBar.h"
- #endif
-
- #ifndef FWKIND_H
- #include "FWKind.h"
- #endif
-
- #ifndef FWINCVW_H
- #include "FWIncVw.h"
- #endif
-
- // ----- OS Layer -----
-
- #ifndef FWMENU_H
- #include "FWMenu.h"
- #endif
-
- #ifndef FWCFMRES_H
- #include "FWCFMRes.h"
- #endif
-
- #ifndef FWRESTYP_H
- #include "FWResTyp.h"
- #endif
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWEVENT_H
- #include "FWEvent.h"
- #endif
-
- #ifndef FWPICSHP_H
- #include "FWPicShp.h"
- #endif
-
- #ifndef SLMixOS_H
- #include "SLMixOS.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRS_H
- #include "FWStrs.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- PPob View Support -----
-
- #if FW_PPOB_VIEWS
- #include "FWPPobRd.h"
- #endif
-
- //========================================================================================
- // Runtime info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfform
- #endif
-
- FW_DEFINE_AUTO(CFormPart)
-
- //========================================================================================
- // CFormPart class
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormPart constructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::CFormPart(ODPart* odPart) :
- FW_CPart(odPart, FW_gInstance, kPartInfoID),
- fTextData(""),
- fIsForm(TRUE),
- fMainPresentation(NULL),
- fPwdDialogPresentation(NULL)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart destructor
- //----------------------------------------------------------------------------------------
-
- CFormPart::~CFormPart()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::Initialize
- //----------------------------------------------------------------------------------------
-
- void CFormPart::Initialize(Environment* ev, ODStorageUnit* storageUnit, FW_Boolean fromStorage) // Override
- {
- FW_CPart::Initialize(ev, storageUnit, fromStorage);
-
- // ----- Register our Presentations
- // By not passing a view id for fMainPresentation we force ODF to call our frame's
- // CreateSubView method.
- #if FW_ODFRC_VIEWS
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, kEmbeddedFormView, kRootFormView);
- fPrintPresentation = RegisterPresentation(ev, kPrintPresentation, FALSE, kPrintFormView, kPrintFormView);
- fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE,
- kPasswordDialog, kPasswordDialog, NULL);
- #else
- fMainPresentation = RegisterPresentation(ev, kMainPresentation, TRUE, NULL);
- fPrintPresentation = RegisterPresentation(ev, kPrintPresentation, FALSE, NULL);
- fPwdDialogPresentation = RegisterPresentation(ev, kPasswordDialogPresentation, FALSE, NULL);
- #endif
-
- // ----- Register one extra kind -----
- // This seems to fix a problem with enabling Paste in the
- // custom text field. It may not be the right thing to do.
- RegisterKind(ev, 'TEXT', kODPlatformDataType, FW_kDataInterchangeStorage, FW_kImportExportEnabled);
-
- //
- // Make sure that classes created from PPob resources
- // won't be dead-stripped!
- //
-
- #if FW_PPOB_VIEWS
- FW_CPPobReader::RegisterAllPPClasses();
- FW_CPPobReader::RegisterClass('Frmv', ReadFormView);
- FW_CPPobReader::RegisterClass('PwEd', ReadPasswordEditView);
- FW_CPPobReader::RegisterClass('ScEd', ReadScrollingEdit);
- #endif
-
- //
- // Make sure that classes created from ODFRC resources
- // won't be dead-stripped!
- //
-
- #if FW_ODFRC_VIEWS
- FW_DO_NOT_DEAD_STRIP(CFormView);
- /*NEW*/ FW_DO_NOT_DEAD_STRIP(FW_CGraphicControl);
- FW_DO_NOT_DEAD_STRIP(FW_CIncludeView);
- FW_DO_NOT_DEAD_STRIP(FW_CGrowBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBarScroller);
- FW_DO_NOT_DEAD_STRIP(FW_CGroupBox);
- FW_DO_NOT_DEAD_STRIP(FW_CScrollBar);
- FW_DO_NOT_DEAD_STRIP(FW_CEditView);
- FW_DO_NOT_DEAD_STRIP(FW_CListBox);
- FW_DO_NOT_DEAD_STRIP(FW_CButton);
- FW_DO_NOT_DEAD_STRIP(FW_CRadioCluster);
- FW_DO_NOT_DEAD_STRIP(FW_CPopupMenu);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewPartContent
- //----------------------------------------------------------------------------------------
- // ODF Method
-
- FW_CContent* CFormPart::NewPartContent(Environment* ev)
- {
- return (FW_NEW(CFormContent, (ev, this)));
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::NewFrame
- //----------------------------------------------------------------------------------------
-
- FW_CFrame* CFormPart::NewFrame(Environment* ev,
- ODFrame* odFrame,
- FW_CPresentation* presentation,
- FW_Boolean fromStorage) // Override
- {
- FW_UNUSED(fromStorage);
- FW_CFrame* newFrame = NULL;
-
- if (presentation == fMainPresentation || presentation == fPrintPresentation) {
- // Create the frame for the main presentation
- newFrame = FW_NEW(CFormFrame, (ev, odFrame, presentation, this));
- }
- else if (presentation == fPwdDialogPresentation) {
- // Create the frame for the dialog presentation, using an ODFRC resource id
- newFrame = FW_NEW(CPwdDialogFrame, (ev, odFrame, presentation, this));
- }
-
- return newFrame;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoMenu
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent) // Override
- {
- FW_Handled menuHandled = FW_kHandled;
- ODCommandID id = theMenuEvent.GetCommandID(ev);
-
- switch (id)
- {
- case cResetFormCommand:
- DoFormCommand(ev);
- break;
-
- #if FW_PPOB_VIEWS && defined(FW_DEBUG)
- case cReloadPPobViews:
- // Reload the views from an external resource file.
- FW_CFrame* frame = GetLastActiveFrame(ev);
- CFormFrame* formFrame = FW_DYNAMIC_CAST(CFormFrame, frame);
- if (formFrame)
- FW_CPPobReader::RecreateViews (ev, kRootFormView, formFrame, formFrame);
- break;
- #endif
- default:
- menuHandled = FW_kNotHandled;
- }
-
- return menuHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoAbout
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoAbout(Environment* ev)
- {
- ::FW_About(ev, this, kAbout);
-
- return FW_kHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoAdjustMenus
- //----------------------------------------------------------------------------------------
-
- FW_Handled CFormPart::DoAdjustMenus(Environment* ev, FW_CMenuBar* menuBar,
- FW_Boolean hasMenuFocus,
- FW_Boolean isRoot) // Override
- {
- FW_UNUSED(isRoot);
- if (hasMenuFocus)
- {
- // ToDo: should enable command only if the form has changed
- menuBar->EnableCommand(ev, cResetFormCommand, true);
- #if FW_PPOB_VIEWS && defined(FW_DEBUG)
- menuBar->EnableCommand(ev, cReloadPPobViews, true);
- #endif
- }
- return FW_kNotHandled;
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::DoFormCommand
- //----------------------------------------------------------------------------------------
-
- void CFormPart::DoFormCommand(Environment* ev)
- {
- // This sample doesn't use a Content model yet. For now the "reset" command will
- // simply erase the text in the edit-fields of each frame
-
- FW_CPresentationFrameIterator iter(ev, fMainPresentation);
- for (CFormFrame* frame = (CFormFrame*)iter.First(ev); iter.IsNotComplete(ev); frame = (CFormFrame*)iter.Next(ev))
- {
- CFormView* formView = (CFormView*) frame->GetContentView(ev);
- formView->ResetData(ev);
- }
-
- #if 0
- // [LSD] PartMaker-generated code, not used yet because we don't have a content model
-
- // Mark the document as changed so it can be saved
- Changed(ev);
-
- // Mark the display frame as changed, so that containing parts can update links
- fMainPresentation->ContentUpdated(ev);
-
- // Force all frames to be redrawn
- fMainPresentation->Invalidate(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CFormPart::GetResourceString
- //----------------------------------------------------------------------------------------
-
- void CFormPart::GetResourceString(Environment* ev,
- FW_ResourceID multiStringID,
- FW_ResourceID stringID,
- FW_CString& string)
- {
- // ----- Open the resource file for this shared library -----
- FW_PSharedLibraryResourceFile resFile(ev);
-
- // ----- Read the string from the resource file -----
- ::FW_LoadStringByID(ev, resFile, multiStringID, FW_kMultiStringRes, stringID, string);
- }
-
-